package step1;

import java.util.HashMap;

public class HunauCacheProxy implements ThirdPartyhunauLib{
    private ThirdPartyhunauLib hunauService;
    //视频缓冲cacheAll
    private HashMap<String, Video> cacheAll = new HashMap<String, Video>();

    public HunauCacheProxy() {
        /********** Begin *********/
        hunauService = new ThirdPartyhunauClass();

        /********** End *********/
    }
    @Override
    public Video getVideo(String videoId) {
        Video video = cacheAll.get(videoId);
        if (video == null) {
            /********** Begin *********/
            video = hunauService.getVideo(videoId);
            cacheAll.put(videoId, video);

            /********** End *********/

        } else {
            System.out.println("Retrieved video '" + videoId + "' from cache.");
        }
        return video;
    }

    public void reset() {
        cacheAll.clear();
    }
}
